<template>
    <div>
        <el-form :model="form" :rules="rules" ref="form">
            <!-- <input type="text" v-model= "message" style="display: none;"> -->
            <!-- <input type="text" v-model= "title" style="display: none;"> -->
            <el-form-item label="系名" label-width="60px" prop="name">
                <el-input  v-model="form.name"autocomplete="off" ></el-input>
            </el-form-item>
            <el-form-item style=" display: flex; justify-content: flex-end;">
                <el-button type="primary" @click="submit">确定</el-button>
                <el-button @click="qx">取消</el-button>
            </el-form-item>

        </el-form>
    </div>
</template>

<script>
import { departmentedit } from '@/api/department';
import { departmenthq } from '@/api/department';

export default {
    props: ["message"],
    data() {
        return {
            form: {
                id: -1,
                name: ''
            },
            rules: {
                name: [{
                    required: true, message: "请输入系名", trigger: "blur"
                }]
            }

        }
    },

    methods: {
        updata() {
           departmenthq(this.message).then(res=>{
            this.form.id=res.data .id
            this.form.name=res.data.name
           })
        },
        submit(){
            // 触发表单验证
            this.$refs['form'].validate(falg=>{
                if(falg){
                    departmentedit(this.form).then(res=>{
                        if(res?.code===0){
                            this.$message({
                                type:"success",
                                message:"添加成功"
                            })
                            // 通知父级关闭对话框
                            this.$emit("close")
                        }
                        
                    })
                }
            })
            
        },
        qx(){
            this.$emit("close")
        }
    },
    mounted() {
        this.updata()
    }


}</script>